package com.glory.gloryquickui.activity

import android.os.Bundle
import androidx.recyclerview.widget.LinearLayoutManager
import com.glory.gloryquickui.R
import com.glory.gloryquickui.adapter.TablePortraitTextAdapter
import com.glory.gloryquickui.adapter.WorkflowBackInfoAdapter
import com.glory.gloryquickui.base.BaseActivity
import com.glory.gloryquickui.entity.TablePortraitBaseCustomBean
import com.glory.gloryquickui.entity.TablePortraitCustomBean
import com.glory.gloryquickui.viewmodel.LoginViewModel
import com.glory.hiwork.mvvm.bean.ToastMessageBean
import kotlinx.android.synthetic.main.activity_workflowbackinfo.*
import org.json.JSONObject

/**
 *Created:YJ
 *创建时间：2021/6/3
 *Describe:
 */
open class WorkflowBackInfoActivity:BaseActivity<LoginViewModel>() {

    override fun layoutId(): Int {
        return R.layout.activity_workflowbackinfo
    }

    override fun initView(savedInstanceState: Bundle?) {
        setTitle("详情")
        try {
            val json = intent.getStringExtra("DataJson")
            val bodyJson = JSONObject(json)
            val inputJson = bodyJson.getJSONObject("inputData")
            val profilesArray = arrayListOf<TablePortraitCustomBean>()
            val detailsArray = arrayListOf<TablePortraitBaseCustomBean>()
            inputJson.keys().forEach {
                var bean = TablePortraitCustomBean(false)
                bean.textName = it + "："
                bean.textValue = inputJson.getString(it)
                profilesArray.add(bean)

                val jsonArray = inputJson.getJSONArray(it)
                for (i in 0 until jsonArray.length()) {
                    val baseEntity = TablePortraitBaseCustomBean()
                    val arrayList = arrayListOf<TablePortraitCustomBean>()
                    jsonArray.getJSONObject(i).keys().forEach {info->
                        val entity = TablePortraitCustomBean(false)
                        entity.textName = info
                        entity.textValue = jsonArray.getJSONObject(i).getString(info)
                        arrayList.add(entity)
                    }
                    baseEntity.ID = it
                    baseEntity.tablelineData = arrayList
                    detailsArray.add(baseEntity)
                }
            }
            val mLayoutManager = LinearLayoutManager(this)
            inputRv.layoutManager = mLayoutManager
            val mAdapter = TablePortraitTextAdapter(profilesArray)
            inputRv.adapter = mAdapter

            detailsRv.layoutManager = LinearLayoutManager(this)
            val detailsAdapter = WorkflowBackInfoAdapter(detailsArray)
            detailsRv.adapter = detailsAdapter
        } catch (e: Exception) {
            viewModel.defUI.toastEvent.value = ToastMessageBean("数据异常", false)
        }
    }

    override fun initData() {

    }


}